<template>
  <view>
    <u-navbar title="收货地址" back-icon-size="34" title-size="36" :border-bottom="false" title-color="#222222" back-icon-color="#222222"></u-navbar>
    <view class="" style="margin: 20rpx 28rpx; background: #fff; border-radius: 20rpx" v-for="(i, k) in list" :key="k">
      <view class="" style="display: flex; align-items: center; padding: 29rpx 20rpx" @tap="select(i)">
        <view class="">
          <image src="https://wenzhen.jiangkukeji360.com/static/shop/map.png" mode="" style="width: 28rpx; height: 28rpx"></image>
        </view>
        <view class="" style="font-size: 28rpx; padding-left: 24rpx">
          <view class="">
            <text>{{ i.name }}</text>
            <text style="padding-left: 15rpx">{{ i.mobile }}</text>
          </view>
          <view class="" style="width: 517rpx; padding-top: 15rpx">{{ i.city }}{{ i.details }}</view>
        </view>
      </view>
      <!--  -->
      <view class="" style="display: flex; align-items: center; justify-content: space-between; padding: 20rpx">
        <view class="" @tap="she(i.address_id)">
          <radio :checked="i.is_default == 1" style="transform: scale(0.6)" color="#FF6572"></radio>
          <text style="font-size: 24rpx; color: #e70c1e" v-if="i.is_default == 1">已设为默认地址</text>
          <text style="font-size: 24rpx; color: #999999" v-if="i.is_default != 1">设为默认地址</text>
        </view>
        <view class="" style="font-size: 24rpx; color: #999999; display: flex; align-items: center">
          <view class="" style="display: flex; align-items: center; margin-right: 50rpx" @tap="(show = true), (address_id = i.address_id)">
            <image src="https://wenzhen.jiangkukeji360.com/static/shop/del.png" mode="" style="width: 28rpx; height: 28rpx; margin-right: 7rpx"></image>
            <view class="">删除</view>
          </view>

          <view class="" style="display: flex; align-items: center" @tap="edit(i)">
            <image src="https://wenzhen.jiangkukeji360.com/static/shop/edit.png" mode="" style="width: 28rpx; height: 28rpx; margin-right: 7rpx"></image>
            <view class="">修改</view>
          </view>
        </view>
      </view>
    </view>
    <view class="" style="background: #fff; position: fixed; bottom: 0; width: 100%">
      <view class="btnbg" style="margin: 60rpx 115rpx" @tap="add">添加收货地址</view>
    </view>
    <u-modal v-model="show" :content="content" title="" confirm-color="#E50014" :show-cancel-button="true" @confirm="del"></u-modal>
  </view>
</template>

<script>
export default {
  data() {
    return {
      value: '',
      list: [],
      type: 0,
      is_default: 1,
      show: false,
      content: '你确认删除该信息吗？',
      address_id: null,
      id: null
    };
  },
  methods: {
    add() {
      uni.navigateTo({
        url: '/shop/addingaddress/addingaddress'
      });
    },
    myaddss() {
      this.api({
        url: '/api/shop/getAddressList',
        method: 'post'
      }).then((res) => {
        this.list = res.data;
      });
    },
    she(e) {
      this.api({
        url: '/api/shop/setAddressDefault',
        method: 'post',
        data: {
          // default:1,
          address_id: e
        }
      }).then((res) => {
        this.myaddss();
      });
    },
    del(e) {
      this.api({
        url: '/api/shop/delAddress',
        method: 'post',
        data: {
          address_id: this.address_id
        }
      }).then((res) => {
        uni.showToast({
          title: res.msg,
          icon: 'none'
        });
        this.myaddss();
      });
    },
    edit(e) {
      uni.navigateTo({
        url: '/shop/addingaddress/addingaddress?type=' + JSON.stringify(e)
      });
    },
    select(e) {
      if (this.type == 1) {
        let pages = getCurrentPages(); //获取所有页面栈实例列表
        let nowPage = pages[pages.length - 1]; //当前页页面实例
        let prevPage = pages[pages.length - 2]; //上一页页面实例
        // prevPage.$vm.username = e.username;
        // prevPage.$vm.mobile = e.mobile;
        // prevPage.$vm.address = e.address;
        // prevPage.$vm.detail = e.detail;
        // prevPage.$vm.addressid = e.address_id;
        prevPage.$vm.address = e.city + e.details;
        uni.navigateBack();
        console.log(e);
      }
      if (this.type == 2) {
        let pages = getCurrentPages(); //获取所有页面栈实例列表
        let nowPage = pages[pages.length - 1]; //当前页页面实例
        let prevPage = pages[pages.length - 2]; //上一页页面实例

        prevPage.$vm.address = e;
        uni.navigateBack();
        console.log(e);
      }
      if (this.id) {
        this.api({
          url: '/api//shop/orderStatus',
          method: 'post',
          data: {
            order_id: this.id,
            type: 2,
            address_id: e.address_id
            // receive_city:e.city,
            // receive_details:e.details
          }
        }).then((res) => {
          uni.showToast({
            title: res.msg,
            icon: 'none'
          });
          setTimeout(() => {
            uni.navigateBack();
          }, 1000);
        });
      }
    }
  },
  onShow() {
    this.myaddss();
  },
  onLoad(op) {
    if (op.type) {
      this.type = op.type;
    }

    if (op.id) {
      this.id = op.id;
    }
  }
};
</script>

<style>
page {
  background: #f6f6f6;
}
.btnbg {
  height: 80rpx;
  background: linear-gradient(180deg, #e50014, #ff6572);
  border-radius: 40rpx;
  text-align: center;
  line-height: 80rpx;
  color: #fff;
  font-size: 32rpx;
}
</style>
